package cn.anc.aonicardv.bean;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * Created by yangdai on 2017/5/19.
 */

public class AlbumBean extends ResponseResultBean {

    private String date;
    private boolean isCheck;
    private int itemPosition;

    public int getItemPosition() {
        return itemPosition;
    }

    public void setItemPosition(int itemPosition) {
        this.itemPosition = itemPosition;
    }

    public boolean isCheck() {
        return isCheck;
    }

    public void setCheck(boolean check) {
        isCheck = check;
    }

    private int position;

    private List<VideoBean> videoBeanList;

    private List<PhotoBean> photoBeanList;

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public List<VideoBean> getVideoBeanList() {
        return videoBeanList;
    }

    public int getPosition() {
        return position;
    }

    public void setPosition(int position) {
        this.position = position;
    }


    public void setVideoBeanList(List<VideoBean> videoBeanList) {
        this.videoBeanList = videoBeanList;
    }

    public List<PhotoBean> getPhotoBeanList() {
        return photoBeanList;
    }

    public void setPhotoBeanList(List<PhotoBean> photoBeanList) {
        this.photoBeanList = photoBeanList;
    }

    public static void invertOrderList(List<VideoBean> mDataList) {
        Collections.sort(mDataList, new Comparator<VideoBean>() {
            /*
             * int compare(Student o1, Student o2) 返回一个基本类型的整型，
             * 返回负数表示：o1 小于o2，
             * 返回0 表示：o1和o2相等，
             * 返回正数表示：o1大于o2。
             */
            public int compare(VideoBean o1, VideoBean o2) {
                //按照时间大小进行降序排列
                if (getNumOfName(o1.getName()) < getNumOfName(o2.getName())) {
                    return 1;
                }
                if (getNumOfName(o1.getName()) == getNumOfName(o2.getName())) {
                    return 0;
                }
                return -1;
            }
        });

    }
    //将List按照时间倒序排列

    public static long getNumOfName(String mBeanName) {
        if (mBeanName != null) {
            try {
                String name = mBeanName.replace("_", "").replace("-", "").replace(":", "").replace(" ", "");
                long a = Long.parseLong(name);
                return a;
            } catch (Exception e) {

            }
        }
        return 0;

    }



    public static List<AlbumBean> getClassifyAlbumBeanByPhotoBean(List<PhotoBean> photoBeanList) {
        List<AlbumBean> temp = new ArrayList<>();
        if (photoBeanList == null)
            return temp;
        Collections.sort(photoBeanList);
        boolean isAddAlbum = true;
        int c = 0;
        for (int i = 0; i < photoBeanList.size(); i++) {
            if (i != 0) {
                if (photoBeanList.get(i - 1).getDate().equals(photoBeanList.get(i).getDate())) {
                    isAddAlbum = false;
                } else {
                    c++;
                    isAddAlbum = true;
                }
            }

            if (isAddAlbum) {
                List<PhotoBean> temp1 = new ArrayList<>();
                temp1.add(photoBeanList.get(i));
                AlbumBean a = new AlbumBean();
                a.setDate(photoBeanList.get(i).getDate());
                a.setPhotoBeanList(temp1);
                a.setPosition(i);
                temp.add(a);
            } else {
                temp.get(c).getPhotoBeanList().add(photoBeanList.get(i));
            }
        }
        return temp;
    }

    public static List<AlbumBean> getClassifyAlbumBeanByVideoBean(List<VideoBean> videoBeanList) {
        List<AlbumBean> temp = new ArrayList<>();
        boolean isAddAlbum = true;
        int c = 0;
        if (videoBeanList == null)
            return temp;
        Collections.sort(videoBeanList);
        for (int i = 0; i < videoBeanList.size(); i++) {
            if (i != 0) {
                if (videoBeanList.get(i - 1).getDate().equals(videoBeanList.get(i).getDate())) {
                    isAddAlbum = false;
                } else {
                    c++;
                    isAddAlbum = true;
                }
            }

            if (isAddAlbum) {
                List<VideoBean> temp1 = new ArrayList<>();
                temp1.add(videoBeanList.get(i));
                AlbumBean a = new AlbumBean();
                a.setDate(videoBeanList.get(i).getDate());
                a.setVideoBeanList(temp1);
                a.setPosition(i);
                temp.add(a);
            } else {
                temp.get(c).getVideoBeanList().add(videoBeanList.get(i));

            }
        }
        return temp;
    }


    @Override
    public String toString() {
        return "AlbumBean{" +
                "date='" + date + '\'' +
                ", position=" + position +
                ", videoBeanList=" + videoBeanList +
                ", photoBeanList=" + photoBeanList +
                '}';
    }
}
